<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglib.jsp"%>
<%@ attribute name="id" type="java.lang.String" required="true" description="编号"%>
<%@ attribute name="name" type="java.lang.String" required="true" description="名称"%>
<%@ attribute name="title" type="java.lang.String" required="true" description="提示文本"%>
<%@ attribute name="url" type="java.lang.String" required="true" description="请求地址"%>
<%@ attribute name="onchange" type="java.lang.String" required="false" description="改变事件"%>
<%@ attribute name="isCheck" type="java.lang.Boolean" required="false" description="是否有选择框"%>
<%@ attribute name="value" type="java.lang.String" required="false" description="选择值"%>
<%@ attribute name="labelValue" type="java.lang.String" required="false" description="选择值"%>
<%@ attribute name="showBoxType" type="java.lang.String" required="true" description="显示文本档类型"%>
<%@ attribute name="isSearch" type="java.lang.Boolean" required="false" description="是否是展示模式"%>
<input id="${id }" name="${name }" type="hidden" value=${value  } />
<c:choose>
	<c:when test="${ showBoxType  eq 'text' }">
		<input type="text" id="${id }Name" class="form-control" readonly="readonly" style="width: 360px; display: Inline;" value="${labelValue }">
	</c:when>
	<c:otherwise>
		<textarea class="form-control" name="${id }Name" readonly="readonly" style="width: 360px; display: Inline;">${labelValue } </textarea>
	</c:otherwise>
</c:choose>
<c:if test="${ isSearch }" >
<a class="btn btn-outline btn-info" id="${id}Button">
	<i class="fa fa-search"></i>
</a>
</c:if>
&nbsp;&nbsp;
<div class="wrapper wrapper-content" id="treeSelect" style="display: none">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					<div class="form-group ">
						<input type="text" id="searchLable" class="form-control" style="width: 220px; display: Inline;">
						<a class="btn btn-outline btn-info" id='sSearch'>
							<i class="fa fa-search"></i>
						</a>
					</div>
					<div id="sTree"></div>
				</div>
			</div>
		</div>
	</div>
</div>


<script type="text/javascript">
	var flag = ${isCheck};
	var plugins = [ "search" ];
	if (flag) {
		plugins.push("checkbox");
	}

	$(document).ready(function() {
		$("#sSearch").on('click', function() {
			$("#sTree").jstree(true).search($("#searchLable").val());
			return false;
		});

		$('#sTree').jstree({
			'core' : {
				'themes' : {
					"dots" : true
				},
				'data' : {
					"url" : "${url}",
					"dataType" : "json"
				},
			},
			"plugins" : plugins,
			"themes" : {
				"theme" : "default",

			}
		});
		$("#${id}Button").on('click', function() {
			uFlag = false;
			var addBoxIndex = layer.open({
				type : 1,
				title : '${title}',
				content : $("#treeSelect"),
				btn : [ '确认', '取消' ],
				shade : [ 0.8, '#393D49' ],
				offset : [ '100px', '30%' ],
				area : [ '500px', '400px' ],
				zIndex : 19950924,
				maxmin : false,
				yes : function(index) {
					var ref = $('#sTree').jstree(true), sel = ref.get_selected();
					$("#${id }").val(sel[0]);
					$("#${id }Name").val(ref.get_node(ref.get_selected()[0]).text);
					layer.close(addBoxIndex);
					return false;
				},
				full : function(elem) {
				},
				success : function(layero, index) {
				},
				end : function() {
					addBoxIndex = -1;
				}
			});

		});
	});
</script>